//
//  UIBarButtonItem+Extensions.swift
//  Architecture
//
//  Created by XQ on 2017/12/5.
//  Copyright © 2017年 XQ. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    // convenience遍历构造函数
    
    /// 自定义 UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: 字体 默认 16 默认值函数可以自由组合
    ///   - target: target
    ///   - action: Selector
    /// - parameter isBack:   是否是返回按钮，如果是加上箭头
    ///
    /// - returns: UIBarButtonItem

    convenience  init(title: String,fontSize: CGFloat = 16,target: AnyObject?, action: Selector,isBack:Bool = false){
       
        let btn: UIButton = UIButton.xq_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        btn.frame = CGRect(x: 0, y: 0, width: 45, height: 30)
        if isBack {
            let imageName = "icon_arrow_left"
            btn.setImage(UIImage(named: imageName), for:.normal)
            btn.setImage(UIImage(named: imageName), for: .highlighted)
            btn.sizeToFit()
        }
        
        btn.addTarget(target, action: action, for: .touchUpInside)
        // convenience 是遍历构造函数，要用self.init实例化UIBarbuttonItem
        self.init(customView: btn)
    }
}

